<template>
  <div class="common-page f-c">
    <BackPage title="3.0项目" />
    <div class="search-params f-r a-c j-b">
      <el-form inline label-width="100px">
        <el-form-item label="项目名称：">
          <el-input v-model="searchParams.projectName" clearable />
        </el-form-item>
        <el-form-item label="项目类型：">
          <el-select v-model="searchParams.projectType" clearable>
            <el-option v-for="item in options3" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="建设性质：">
          <el-select v-model="searchParams.projectNature" clearable>
            <el-option v-for="item in options1" :key="item.value" :value="item.value" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="地区：">
          <el-input v-model="searchParams.area" clearable />
        </el-form-item>
        <el-form-item label="所属行业：">
          <el-input v-model="searchParams.industryName" clearable />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-box f-g">
      <el-table
        v-loading="loading"
        height="100%"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />

        <el-table-column label="项目名称" min-width="200px">
          <template slot-scope="scope">
            <div class="f-r a-c">
              <img v-if="scope.row.relevance == 1" src="@/assets/important.png" style="width: 30px;height: 30px" alt="">
              <span>{{ scope.row.projectName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="200px">
          <template slot-scope="scope">
            <el-button type="text" @click="onRead(scope.row)">查看</el-button>
<!--            <el-button type="text" @click="onEdit(scope.row)">编辑</el-button>-->
            <el-button type="text" @click="onTag(scope.row)">添加标签</el-button>
            <el-button type="text" @click="onConfig(scope.row)">流程配置</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <ItemDetail ref="ItemDetailRef" />
    <ItemAdd ref="ItemAddRef" @get-page="initData" />
    <ItemTag ref="ItemTagRef" @get-page="initData" />

  </div>
</template>

<script>
import crud from '@/mixins/crud'
import ItemDetail from './detail'
import ItemAdd from './add'
import ItemTag from './tag'
import { area_list, http_project1, http_project2 } from '@/api'
import { deepClone } from '@/utils'
import {project_nature, project_type} from "@/dict";
export default {
  name: 'Index',
  components: {
    ItemAdd,
    ItemDetail,
    ItemTag
  },
  mixins: [crud],
  data() {
    return {
      request: http_project2,
      searchParams: {
        projectName: '',
        projectType: '',
        projectNature: '',
        area: '',
        industryName: ''
      },
      options1: project_nature,
      options2: [
        { value: 0, name: '进行中' },
        { value: 1, name: '已完成' },
        { value: 2, name: '未完成' }
      ],
      options3: project_type,
      columns: [
        { prop: 'projectTypeName', label: '项目类型' },
        { prop: 'projectNatureName', label: '建设性质' },
        { prop: 'industryName', label: '所属行业' },
        { prop: 'area', label: '地区' },
        { prop: 'totalAmount', label: '总投资' },
        { prop: 'progressName', label: '当前进度' }
      ],
      tableData: []
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.projectNatureName = this.options1.find(item => item.value == el.projectNature)?.name
        el.progressName = this.options2.find(item => item.value == el.progress)?.name
        el.projectTypeName = this.options3.find(item => item.value == el.projectType)?.name
      })
    },
    onAdd() {
      this.$refs.ItemAddRef.open()
    },
    onEdit(item) {
      this.$refs.ItemAddRef.open(item)
    },
    onConfig(item) {
      this.$router.push({
        path: '/project/config-edit',
        query: {
          projectId: item.id
        }
      })
    },
    onRead(item) {
      this.$refs.ItemDetailRef.open(item)
    },
    onTag(item) {
      this.$refs.ItemTagRef.open(item)
    }
  }
}
</script>
